package com.zhuhjay.controller;

import com.zhuhjay.model.domain.HttpResult;
import com.zhuhjay.model.dto.MemberInsertDto;
import com.zhuhjay.model.dto.MemberRechargeDto;
import com.zhuhjay.model.dto.MemberUpdateDto;
import com.zhuhjay.model.vo.MemberVo;
import com.zhuhjay.service.MemberService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ZhuHJay
 * @date 2023/4/26 17:47
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Resource
    private MemberService memberService;

    @GetMapping("delete.auth")
    public HttpResult<?> delete(@RequestParam("id") Integer id) {
        memberService.delete(id);
        return HttpResult.ok();
    }

    @PostMapping("update.auth")
    public HttpResult<?> update(@RequestBody @Validated MemberUpdateDto memberVo) {
        memberService.update(memberVo);
        return HttpResult.ok();
    }

    @GetMapping("one.auth")
    public HttpResult<MemberVo> one(@RequestParam("id") Integer id) {
        return HttpResult.ok(memberService.one(id));
    }

    @PostMapping("insert.auth")
    public HttpResult<?> insert(@RequestBody @Validated MemberInsertDto memberDto) {
        memberService.insert(memberDto);
        return HttpResult.ok();
    }

    @PostMapping("recharge.auth")
    public HttpResult<?> recharge(@RequestBody @Validated MemberRechargeDto dto) {
        memberService.recharge(dto);
        return HttpResult.ok();
    }

    @GetMapping("list.auth")
    public HttpResult<List<MemberVo>> list() {
        return HttpResult.ok(memberService.list());
    }

}
